<template>
	<view>
		<nav-custom :name="title"></nav-custom>
		<view class="list">
			<view class="list_a bor_bot">
				<view class="grey_h_28 list_c" v-for="(item,index) in dataList" @click="dianji(index)"
					:class="active == index?'list_choose black_f_28':'grey_h_28 list_c'">
					{{item.data}}
				</view>
			</view>
			<view class="back bor_bot" v-if="statistics.revenue_statistics">
				<view class="dis_f_l_c">
					<view class="black_f_28">收益统计</view>
					<view class="grey_s_24" style="margin-left: 10rpx;">统计时间 {{fullDateStr}}</view>
				</view>
				<view class="list_b dis_f_sb_c">
					<view style="width: 294rpx;">
						<view class="grey_f_24 bor_b_16">今日收益(元)</view>
						<view class="black_f_40">{{statistics.revenue_statistics.today_money}}</view>
					</view>
					<view class="b_xian"></view>
					<view style="width: 294rpx;">
						<view class="grey_f_24 bor_bot">
							昨日全天<text class="black_s_24">￥{{statistics.revenue_statistics.yesterday_money}}</text>
						</view>
						<view class="grey_f_24">
							昨日此刻<text class="black_s_24">￥{{statistics.revenue_statistics.yesterday_cs_money}}</text>
						</view>
					</view>
				</view>
				<view class="list_d">
					<view class="list_d_a dis_f_co_c_c bor_bot">
						<view class="black_f_32 bor_b_16">{{statistics.revenue_statistics.zf_people}}</view>
						<view class="grey_f_24">支付人数</view>
					</view>
					<view class="list_d_a dis_f_co_c_c bor_bot">
						<view class="black_f_32 bor_b_16">{{statistics.revenue_statistics.zf_count}}</view>
						<view class="grey_f_24">订单数(笔)</view>
					</view>
					<view class="list_d_a dis_f_co_c_c bor_bot">
						<view class="black_f_32 bor_b_16">{{statistics.revenue_statistics.customer_unit_price}}</view>
						<view class="grey_f_24">客单价(元)</view>
					</view>
					<view class="list_d_a dis_f_co_c_c">
						<view class="black_f_32 bor_b_16">{{statistics.revenue_statistics.to_be_credited}}</view>
						<view class="grey_f_24">待入账(元)</view>
					</view>
					<view class="list_d_a dis_f_co_c_c">
						<view class="black_f_32 bor_b_16">{{statistics.revenue_statistics.to_be_paid}}</view>
						<view class="grey_f_24">待支付</view>
					</view>
					<view class="list_d_a dis_f_co_c_c">
						<view class="black_f_32 bor_b_16">{{statistics.revenue_statistics.to_be_shipped}}</view>
						<view class="grey_f_24">待发货</view>
					</view>
				</view>
				<view class="list_e">
					<view class="charts-box">
						<qiun-data-charts type="line" :opts="opts" :chartData="chartData" :ontouch="true"
							@getIndex="getIndex" :tapLegend="false" />
					</view>
				</view>
			</view>
			<view class="back" v-if="statistics.after_sales_statistics">
				<view class="dis_f_l_c">
					<view class="black_f_28">售后统计</view>
					<view class="grey_s_24" style="margin-left: 10rpx;">统计时间 {{fullDateStr}}</view>
				</view>
				<view class="list_b dis_f_sb_c">
					<view style="width: 294rpx;">
						<view class="grey_f_24 bor_b_16">今日退款(元)</view>
						<view class="black_f_40">{{statistics.after_sales_statistics.todays_refund}}</view>
					</view>
					<view class="b_xian"></view>
					<view style="width: 294rpx;">
						<view class="grey_f_24 bor_bot">
							昨日全天<text class="black_s_24">￥{{statistics.after_sales_statistics.refund_yesterday}}</text>
						</view>
						<view class="grey_f_24">
							昨日此刻<text
								class="black_s_24">￥{{statistics.after_sales_statistics.yesterday_at_this_moment}}</text>
						</view>
					</view>
				</view>
				<view class="list_d">
					<view class="list_d_a dis_f_co_c_c bor_bot">
						<view class="black_f_32 bor_b_16">{{statistics.after_sales_statistics.number_of_refunds}}</view>
						<view class="grey_f_24">退款人数</view>
					</view>
					<view class="list_d_a dis_f_co_c_c bor_bot">
						<view class="black_f_32 bor_b_16">{{statistics.after_sales_statistics.Number_of_count}}</view>
						<view class="grey_f_24">订单数(笔)</view>
					</view>
					<view class="list_d_a dis_f_co_c_c bor_bot">
						<view class="black_f_32 bor_b_16">{{statistics.after_sales_statistics.customer_unit_price}}
						</view>
						<view class="grey_f_24">客单价(元)</view>
					</view>
					<view class="list_d_a dis_f_co_c_c">
						<view class="black_f_32 bor_b_16">{{statistics.after_sales_statistics.pending_refund}}</view>
						<view class="grey_f_24">待退款(元)</view>
					</view>
				</view>
				<view class="list_e">
					<view class="charts-box">
						<qiun-data-charts type="line" :opts="opts" :chartData="chartData2" :ontouch="true"
							@getIndex="getIndex" :tapLegend="false" />
					</view>
				</view>
			</view>
		</view>
		<!-- <image class="bo_js_er_img" src="../../static/image/zcxian.png" mode=""></image> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fullDateStr: '',
				statistics: [],
				date: '',
				day: 0,
				res: {
					series: [],
					categories: [],
				},
				res2: {
					series: [],
					categories: [],
				},
				info: '',
				title: "数据统计",
				dataList: [{
					data: "今日"
				}, {
					data: "本月"
				}, {
					data: "全部"
				}],
				active: 0,
				chartData: {},
				chartData2: {},
				url:'',
				opts: {
					tapLegend: false,
					timing: "easeOut",
					duration: 1000,
					rotate: false,
					rotateLock: false,
					color: ["#3377FF", "#5CE500", "#FF6401", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: [15, 10, 0, 15],
					fontSize: 13,
					fontColor: "#666666",
					dataLabel: false,
					dataPointShape: false,
					dataPointShapeType: "hollow",
					touchMoveLimit: 60,
					enableScroll: true,
					canvas2d: true,
					enableMarkLine: false,
					legend: {
						show: true,
						position: "bottom",
						float: "center",
						padding: 5,
						margin: 5,
						backgroundColor: "rgba(254,61,61,0)",
						borderColor: "rgba(255,112,112,0)",
						borderWidth: 0,
						fontSize: 13,
						fontColor: "#666666",
						lineHeight: 11,
						hiddenColor: "#CECECE",
						itemGap: 10
					},
					xAxis: {
						disableGrid: true,
						disabled: false,
						axisLine: true,
						axisLineColor: "#F7FAFF",
						calibration: false,
						fontColor: "#8e8e8e",
						fontSize: 13,
						lineHeight: 20,
						marginTop: 0,
						rotateLabel: false,
						rotateAngle: 45,
						itemCount: 5,
						boundaryGap: "center",
						splitNumber: 5,
						gridColor: "#a6a6a6",
						gridType: "solid",
						dashLength: 4,
						gridEval: 1,
						scrollShow: false,
						scrollAlign: "left",
						scrollColor: "#A6A6A6",
						scrollBackgroundColor: "#EFEBEF",
						title: "",
						titleFontSize: 13,
						titleOffsetY: 0,
						titleOffsetX: 0,
						titleFontColor: "#666666",
						format: ""
					},
					yAxis: {
						gridType: "dash",
						dashLength: 2,
						disabled: true,
						disableGrid: false,
						splitNumber: 5,
						gridColor: "#dbdbdb",
						padding: 10,
						showTitle: false,
						data: []
					},
					extra: {
						line: {
							type: "curve",
							width: 2,
							activeType: "hollow",
							linearType: "none",
							onShadow: true,
							animation: "vertical"
						},
						tooltip: {
							showBox: true,
							showArrow: false,
							showCategory: false,
							borderWidth: 0,
							borderRadius: 7,
							borderColor: "#ffffff",
							borderOpacity: 0.7,
							bgColor: "#EBF2FF",
							bgOpacity: 0.7,
							gridType: "solid",
							dashLength: 4,
							gridColor: "#C2D7FF",
							boxPadding: 3,
							fontSize: 13,
							lineHeight: 20,
							fontColor: "#999CA3",
							legendShow: true,
							legendShape: "circle",
							splitLine: true,
							horizentalLine: false,
							xAxisLabel: false,
							yAxisLabel: false,
							labelBgColor: "#d24343",
							labelBgOpacity: 0.7,
							labelFontColor: "#666666"
						},
						markLine: {
							type: "solid",
							dashLength: 4,
							data: []
						}
					}
				}
			}
		},
		onLoad() {
			this.url=this.$.ajax_url3
			let date = new Date();
			let year = date.getFullYear();
			let month = date.getMonth() + 1;
			let day = date.getDate();
			let hours = date.getHours();
			let minutes = date.getMinutes();
			let seconds = date.getSeconds();
			this.fullDateStr = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			this.date = new Date().toISOString().slice(0, 10)
			this.day = new Date(year, month, 0).getDate();
		},
		onShow() {
			this.get_statistics()
		},
		// onReady() {
		// 	this.getServerData();
		// },
		methods: {
			get_statistics() {
				this.$.ajax(1, 'post', 'store/store/data_statistics', {
					type: this.active,
					day: this.day,
					start: this.date,
					end: this.date,
				}, (res) => {
					if (res.code == 200) {
						this.statistics = res.data
						this.info = res.data;
						console.log(this.info.after_sales_statistics.customer_unit_price);
						this.res.series = this.info.after_sales_statistics.tb.series;
						this.res.categories = this.info.after_sales_statistics.tb.categories;
						this.chartData = JSON.parse(JSON.stringify(this.res));
						this.res2.series = this.info.revenue_statistics.tb.series;
						this.res2.categories = this.info.revenue_statistics.tb.categories;
						this.chartData2 = JSON.parse(JSON.stringify(this.res2));
						console.log(this.chartData2,'aaaa');
						console.log(this.chartData,'aaaa');
					} else {
						this.$.ti_shi(res.msg)
					}
				});
			},
			dianji(index) {
				this.active = index
				this.get_statistics()
			},
			getServerData(tb) {
				//模拟从服务器获取数据时的延时
				setTimeout(() => {
					//模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
					let res = {
						categories: tb.categories,
						series: tb.series,
					};
					this.chartData = JSON.parse(JSON.stringify(res));
				}, 500);
			},

			getServerData2(tb) {
				//模拟从服务器获取数据时的延时
				setTimeout(() => {
					//模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
					let res = {
						categories: tb.categories,
						series: tb.series,
					};
					this.chartData2 = JSON.parse(JSON.stringify(res));
				}, 500);
			},
		}
	}
</script>

<style lang="scss">
	.list_a {
		width: 280rpx;
		height: 68rpx;
		background: #F7F7F7;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;

		.list_c {
			width: 88rpx;
			height: 52rpx;
			text-align: center;
			line-height: 52rpx;
		}

		.list_choose {
			width: 88rpx;
			height: 52rpx;
			background: #FFFFFF;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			text-align: center;
			line-height: 52rpx;
		}
	}

	.list_b {
		width: 590rpx;
		height: 120rpx;
		background: #F7FAFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 24rpx;
		margin-top: 24rpx;

		.b_xian {
			width: 2rpx;
			height: 32rpx;
			background-color: #CCCED1;
			margin: 0 26rpx;
		}
	}

	.list_d {
		display: flex;
		flex-wrap: wrap;
		margin-top: 32rpx;

		.list_d_a {
			width: 209rpx;
			height: 100rpx;
		}
	}

	.list_e {
		width: 638rpx;
		height: 500rpx;
	}

	.charts-box {
		width: 650rpx;
		height: 500rpx;
	}
</style>